/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.converter;

import br.com.foxline.model.ActCep;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author roniere
 */
@FacesConverter(value = "actcepconverter")
public class ActCepConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        ActCep actCep = new ActCep();
        try {
            actCep.setId((Long.valueOf(value)));
        } catch (Exception e) {
            System.err.println("ERRO NA CONVERSÃO");
            e.printStackTrace();
            return null;
        }
        return actCep;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        ActCep actCep = (ActCep) value;
        return actCep.getId() + "";
    }
}
